package tw.raybird.walker.officereader;

import java.io.File;
import java.util.HashMap;

import org.apache.log4j.Logger;

/**
 * 文字讀取操作者
 * @author raybird
 *
 */
public class ReaderOperator {

	/**	日誌器 */
	private Logger logger;
	/** 文字讀取器集合*/
	private HashMap<String, Reader> readMap;
	
	
	public ReaderOperator(){
		logger = Logger.getRootLogger();
		readMap = new HashMap<String, Reader>();
	}
	
	public void addReader(String name ,Reader reader){
		logger.info("增加:"+ name + "Reader");
		readMap.put(name, reader);
	}
	
	/**
	 * 讀取檔案文字內容
	 * @param file 檔案內容
	 * @param type 檔案型態，參考Reader內的參數
	 * @return
	 */
	public String read(File file , String type){
		String content = "";
		if(file.exists() && file.isFile()){
			content = readMap.get(type).read(file);					
		}
		return content;
	}
}
